//import 'package:amap_base/amap_base.dart';

import 'dart:async';
import 'dart:convert';

import 'package:barcode_scan/barcode_scan.dart';
import 'package:date_format/date_format.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:flutter_hotwork/HomePage.dart';
import 'package:flutter_hotwork/Myapplication.dart';
import 'package:flutter_hotwork/bean/AreaDeviceBean.dart';
import 'package:flutter_hotwork/bean/BaseBean.dart';
import 'package:flutter_hotwork/home/RoadChoice.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';
import 'package:flutter_hotwork/utils/DioUtils.dart';
import 'package:flutter_hotwork/xunjian/XunJianGuZhangShangBao.dart';
import 'package:flutter_hotwork/xunjian/XunJianWenTiShangBao.dart';
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';

import '../LoadingDialog.dart';
import '../Toast.dart';

class XunJianAreaDeviceActivity extends StatefulWidget {
  @override
  baseState createState() => new baseState();
}

class baseState extends State<XunJianAreaDeviceActivity> {

  AreaDeviceBean areaDeviceBean;
  @override
  void initState() {
    super.initState();
    DioUtils.createInstance();
    queryData();
  }
//手机号的控制器
  @override
  void dispose() {
//    _amapLocation.stopLocate();
    super.dispose();
  }
  ScrollController controller = ScrollController();
  ///接收选择的结果

  @override
  Widget build(BuildContext context) {
    double rpx = MediaQuery
        .of(context)
        .size
        .height / 800;
    double rpxw = MediaQuery
        .of(context)
        .size
        .width / 750;
    return Scaffold(
      appBar:new BaseViewBar(
          childView:
          Column(
            children: [
              new BaseTitleBar(
                "检查项目",
                leftIcon: 'images/fanhui.png',
                rightIcon:  "",
                rightClick: () {
                  print("点击了右边干嘛啊。。。哦");
                },
                leftClick: () {
                  Navigator.of(context).pop();
                },
              )
              ,
            ],
          ),
          preferredSize: Size.fromHeight(58.0)

      ),
      body:
      Container(
          padding: EdgeInsets.only(left: 10),
          child:
          Column(
            children: [
              areaDeviceBean!=null?
              Container(
                child:
                Expanded(
                  child: (
                    genContentList(
                        areaDeviceBean.result,context, controller
                    )
                  ),
                ),


              )
                  : Container(),
            ],
          )
      ),
    );
  }
  genContentList(List<AreaDevice> data, BuildContext context, controller) {
    double rpx = MediaQuery
        .of(context)
        .size
        .width / 750;

    return ListView.builder(
      shrinkWrap: true,
      controller: controller,
      itemCount: data.length,
      itemBuilder: (BuildContext context, int index) {
        return
          InkWell(
              child: Card(
                // padding: EdgeInsets.only(left: 10, right: 10, top: 0, bottom: 0),
                child:
                Column(
                  mainAxisSize: MainAxisSize.max,
//                交叉轴的布局方式，对于column来说就是水平方向的布局方式
                  crossAxisAlignment: CrossAxisAlignment.start,
                  //就是字child的垂直布局方向，向上还是向下
                  children: [
                    Container(height: 5,),
                    Row(
                      mainAxisSize: MainAxisSize.max,
//                交叉轴的布局方式，对于column来说就是水平方向的布局方式
                      crossAxisAlignment: CrossAxisAlignment.center,
                      //就是字child的垂直布局方向，向上还是向下
                      verticalDirection: VerticalDirection.down,
                      children: [
                        Container(
                          width: 10,
                        ),
                        Container(
                            child:
                            Text("设备名称："+data[index].deviceName,
                              style: TextStyle(color: Colors.black, fontSize: 10,),
                            )
                        ),
                        Container(
                          width: 10,
                        ),
                        Container(
                            child:
                            Text("类型："+data[index].deviceTypeName,
                              style: TextStyle(color: Colors.black, fontSize: 10,),
                            )
                        ),
                        Container(
                          width: 10,
                        ),
                        Container(
                            child:
                            Text("编码："+data[index].deviceCode,
                              style: TextStyle(color: Colors.black, fontSize: 10,),
                            )
                        ),

                      ],

                    ),
                    Container(height: 5,),
                    Text("    检查项目："+data[index].projectName,
                      style: TextStyle(color: Colors.black, fontSize: 10,),
                    ),
                    Container(height: 5,),
                    Text("    检查内容："+data[index].projectContext,
                      style: TextStyle(color: Colors.black, fontSize: 10,),
                    ),
                    Container(height: 5,),
                    Row(children: [
                      Flexible(fit: FlexFit.tight, child: SizedBox()),
                      // InkWell(
                      //   onTap: (){
                      //     Navigator.push(context, MaterialPageRoute(builder: (context) {
                      //       MyApplication.areaDeviceBean = data[index];
                      //       return new XunJianGuzhangEditScreen();
                      //     }));
                      //   },
                      //   child:
                      //   Container(
                      //       width: 50,
                      //       height: 20,
                      //       margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                      //       padding:  EdgeInsets.only(left: 2, right: 2, top:0, bottom: 0),
                      //       decoration: BoxDecoration(
                      //         // border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                      //         color: Colors.blue, // 底色
                      //         borderRadius: new BorderRadius.circular((5.0)), // 圆角度
                      //       ),
                      //       child:
                      //       Row(
                      //         mainAxisAlignment:MainAxisAlignment.center,
                      //         children: [
                      //           Text("故障上报",
                      //             style: TextStyle(color: Colors.white,fontSize: 10),
                      //           )
                      //
                      //         ],
                      //       )
                      //   ),
                      // ),  na'ge
                      InkWell(
                        onTap: (){
                          Navigator.push(context, MaterialPageRoute(builder: (context) {
                            // MyApplication.areaDeviceBean = data[index];
                            return new XunJianEditScreen();
                          }));
                        },
                        child:
                        Container(
                            width: 50,
                            height: 20,
                            margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                            padding:  EdgeInsets.only(left: 2, right: 2, top:0, bottom: 0),
                            decoration: BoxDecoration(
                              // border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                              color: Colors.blue, // 底色
                              borderRadius: new BorderRadius.circular((5.0)), // 圆角度
                            ),
                            child:
                            Row(
                              mainAxisAlignment:MainAxisAlignment.center,
                              children: [
                                Text("问题上报",
                                  style: TextStyle(color: Colors.white,fontSize: 10),
                                )
                              ],
                            )
                        ),
                      ),
                      Container(width: 5,),
                    ],),

                    Container(height: 5,),
                  ],),


              ))
        ;
        // Expanded(
        //   child:
        // Flexible(
        //   child:
        // getItemContentList(data[index].focusHotUserVos,context,controller),
        // )
        // )

      },
    );
  }
//获取区域
  void queryData() async {
    // Navigator.pop(context);
    try {
      Response response;
      response = await DioUtils.dio.get(
          DioUtils.API_PREFIX + "/checkTask/listDeviceProjectByAreaId?areaId="+MyApplication.areaId.toString()+"&taskId="+MyApplication.nowtaskbean.id.toString()+"&inspectorId="+MyApplication.inspacterId.toString());
      Map respMap = json.decode(response.data);
      areaDeviceBean = AreaDeviceBean.fromJson(respMap);
      if(null!= areaDeviceBean.result&&areaDeviceBean.result.length>0){
        MyApplication.deviceId = areaDeviceBean.result[0].deviceId;
      }

      setState(() {
      });
    } catch (e) {
      print('请求出错：' + e.toString());
    }
  }
}






















